package com.csea.demo.service.serviceImpl;

import com.csea.demo.pojo.UsersEntity;
import com.csea.demo.mapper.UsersMapper;
import com.csea.demo.service.UsersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Csea
 * @since 2020-02-26
 */
@Service
@Slf4j
public class UsersServiceImpl extends ServiceImpl<UsersMapper, UsersEntity> implements UsersService {
    @Resource
    private UsersMapper usersMapper;

//    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void add(UsersEntity usersEntity) {
        usersMapper.insert(usersEntity);
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public void addS(UsersEntity usersEntity) {
        usersMapper.insert(usersEntity);
    }

    @Transactional(propagation = Propagation.MANDATORY)
    @Override
    public void addM(UsersEntity usersEntity) {
        usersMapper.insert(usersEntity);
    }

    @Transactional(propagation = Propagation.NEVER)
    @Override
    public void addNever(UsersEntity usersEntity) {
        usersMapper.insert(usersEntity);
    }

    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    @Override
    public void addNotSupport(UsersEntity usersEntity) {
        usersMapper.insert(usersEntity);
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Override
    public void addNew(UsersEntity usersEntity) {
        usersMapper.insert(usersEntity);
    }

    @Transactional(propagation = Propagation.NESTED)
    @Override
    public void addNested(UsersEntity usersEntity) {
        usersMapper.insert(usersEntity);
        log.info("value={}", 1 / 0);
    }
}
